﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TfsBugger
{
    static class Program
    {
        #region Common Properties/Objects
        public static TeamFoundationServer TfsServer { get; set; }

        public static Project[] SelectedProjects { get; set; } 

        public static AppShell Shell { get; set; }

        public static bool IsTfsLoaded
        {
            get { return null != TfsServer && TfsServer.HasAuthenticated && null != SelectedProjects && SelectedProjects.Length > 0; }
        }
        #endregion


        #region Entry Point
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Enforce single-instance app
            Mutex mut = new Mutex(false, Marshal.GetTypeLibGuidForAssembly(Assembly.GetExecutingAssembly()).ToString());
            if (mut.WaitOne(0, false))
            {
                var shell = new AppShell();
                Shell = shell;
                Application.Run(shell);

                mut.Close();
            }
        } 
        #endregion
    }
}
